package com.pw.study.flink.transform;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class TransFormKeyBy {
    public static void main(String[] args) {
        dealKeyBy();

    }


    private static void dealKeyBy() {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(3);
        DataStreamSource<Integer> stream = env.fromElements(1, 2, 3, 4, 5, 6);
        stream.keyBy(x->x%2==0?"偶数":"奇数").print();
        env
                .fromElements(10, 3, 5, 9, 20, 8)
                .keyBy(value -> value % 2 == 0 ? "偶数" : "奇数")
                .print("艺术：");


        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
